import sqlite3

def create_table(conn):
    cursor = conn.cursor()
    cursor.execute('''
        CREATE TABLE IF NOT EXISTS employees (
            id INTEGER PRIMARY KEY,
            name TEXT NOT NULL,
            department TEXT,
            salary REAL
        )
    ''')
    conn.commit()

def insert_employee(conn, name, department, salary):
    cursor = conn.cursor()
    cursor.execute("INSERT INTO employees (name, department, salary) VALUES (?, ?, ?)", (name, department, salary))
    conn.commit()
    return cursor.lastrowid

def update_employee_salary(conn, employee_id, new_salary):
    cursor = conn.cursor()
    cursor.execute("UPDATE employees SET salary = ? WHERE id = ?", (new_salary, employee_id))
    conn.commit()

def query_employees(conn, department=None):
    cursor = conn.cursor()
    if department:
        cursor.execute("SELECT * FROM employees WHERE department = ?", (department,))
    else:
        cursor.execute("SELECT * FROM employees")
    rows = cursor.fetchall()
    return rows

def main():
    conn = sqlite3.connect('employee_database.db')
    create_table(conn)

    # Insert some employees
    insert_employee(conn, 'John Doe', 'IT', 60000)
    insert_employee(conn, 'Jane Smith', 'HR', 55000)
    insert_employee(conn, 'Peter Jones', 'Sales', 70000)


    # Update an employee's salary
    update_employee_salary(conn, 1, 65000)

    # Query employees
    all_employees = query_employees(conn)
    print("All employees:")
    for row in all_employees:
        print(row)

    it_employees = query_employees(conn, 'IT')
    print("\nIT employees:")
    for row in it_employees:
        print(row)


    conn.close()

if __name__ == "__main__":
    main()


